package com.lin.eat.entry;


import java.io.Serializable;

public class ServerResponse<T> implements Serializable {

    private int code;
    private String message;
    private boolean ok;
    private T data;

    public ServerResponse() {
    }

    public ServerResponse(int code, String message, boolean ok, T data) {
        this.code = code;
        this.message = message;
        this.ok = ok;
        this.data = data;
    }

    public static <T> ServerResponse<T> createBySuccess(T data){
        return new ServerResponse<>(200,"成功",true,data);
    }

    public static <T> ServerResponse<T> createByError(T data){
        return new ServerResponse<>(201,"失败",false,data);
    }

    @Override
    public String toString() {
        return "ServerResponse{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", ok=" + ok +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isOk() {
        return ok;
    }

    public void setOk(boolean ok) {
        this.ok = ok;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
